
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>socket.io API · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="emit.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="socket.io-api.html">
            
                <a href="socket.io-api.html">
            
                    
                    socket.io API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="emit.html">
            
                <a href="emit.html">
            
                    
                    emit
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="socket.io-client-api.html">
            
                <a href="socket.io-client-api.html">
            
                    
                    socket.io-client API
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >socket.io API</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#server">Class: Server</a><ul>
<li><a href="#new-serverhttpserver-options">new Server(httpServer[, options])</a></li>
<li><a href="#new-serverport-options">new Server(port[, options])</a></li>
<li><a href="#new-serveroptions">new Server(options)</a></li>
<li><a href="#serversockets">server.sockets</a></li>
<li><a href="#serverserveclientvalue">server.serveClient([value])</a></li>
<li><a href="#serverpathvalue">server.path([value])</a></li>
<li><a href="#serveradaptervalue">server.adapter([value])</a></li>
<li><a href="#serveroriginsvalue">server.origins([value])</a></li>
<li><a href="#serveroriginsfn">server.origins(fn)</a></li>
<li><a href="#serverattachhttpserver-options">server.attach(httpServer[, options])</a></li>
<li><a href="#serverattachport-options">server.attach(port[, options])</a></li>
<li><a href="#serverlistenhttpserver-options">server.listen(httpServer[, options])</a></li>
<li><a href="#serverlistenport-options">server.listen(port[, options])</a></li>
<li><a href="#serverbindengine">server.bind(engine)</a></li>
<li><a href="#serveronconnectionsocket">server.onconnection(socket)</a></li>
<li><a href="#serverofnsp">server.of(nsp)</a></li>
<li><a href="#serverclosecallback">server.close([callback])</a></li>
</ul>
</li>
<li><a href="#namespace">Class: Namespace</a><ul>
<li><a href="#namespacename">namespace.name</a></li>
<li><a href="#namespaceconnected">namespace.connected</a></li>
<li><a href="#namespaceemiteventname-args">namespace.emit(eventName[, ...args])</a></li>
<li><a href="#namespaceclientscallback">namespace.clients(callback)</a></li>
<li><a href="#namespaceusefn">namespace.use(fn)</a></li>
<li><a href="#event-connect">Event: &apos;connect&apos;</a></li>
<li><a href="#event-connect">Event: &apos;connection&apos;</a></li>
<li><a href="#flag-volatile">Flag: &apos;volatile&apos;</a></li>
<li><a href="#flag-local">Flag: &apos;local&apos;</a></li>
</ul>
</li>
<li><a href="#socket">Class: Socket</a><ul>
<li><a href="#socketid">socket.id</a></li>
<li><a href="#socketrooms">socket.rooms</a></li>
<li><a href="#socketclient">socket.client</a></li>
<li><a href="#socketconn">socket.conn</a></li>
<li><a href="#socketrequest">socket.request</a></li>
<li><a href="#socketusefn">socket.use(fn)</a></li>
<li><a href="#socketsendargs-ack">socket.send([...args][, ack])</a></li>
<li><a href="#socketemiteventname-args-ack">socket.emit(eventName[, ...args][, ack])</a></li>
<li><a href="#socketoneventname-callback">socket.on(eventName, callback)</a></li>
<li><a href="#socketjoinroom-callback">socket.join(room[, callback])</a></li>
<li><a href="#socketjoinrooms-callback">socket.join(rooms[, callback])</a></li>
<li><a href="#socketleaveroom-callback">socket.leave(room[, callback])</a></li>
<li><a href="#sockettoroom">socket.to(room)</a></li>
<li><a href="#socketinroom">socket.in(room)</a></li>
<li><a href="#socketcompressvalue">socket.compress(value)</a></li>
<li><a href="#socketdisconnectclose">socket.disconnect(close)</a></li>
<li><a href="#flag-broadcast">Flag: &apos;broadcast&apos;</a></li>
<li><a href="#flag-volatile-1">Flag: &apos;volatile&apos;</a></li>
<li><a href="#event-disconnect">Event: &apos;disconnect&apos;</a></li>
<li><a href="#event-error">Event: &apos;error&apos;</a></li>
<li><a href="#event-disconnecting">Event: &apos;disconnecting&apos;</a></li>
</ul>
</li>
<li><a href="#client">Class: Client</a><ul>
<li><a href="#clientconn">client.conn</a></li>
<li><a href="#clientrequest">client.request</a></li>
</ul>
</li>
</ul>
<h3 id="server">Server</h3>
<p>&#x66B4;&#x9732;&#x4E8E; <code>require(&apos;socket.io&apos;)</code>.</p>
<h4 id="new-serverhttpserver-options">new Server(httpServer[, options])</h4>
<ul>
<li><code>httpServer</code> <em>(http.Server)</em> &#x670D;&#x52A1;&#x5668;&#x7ED1;&#x5B9A;&#x3002;</li>
<li><code>options</code> <em>(Object)</em><ul>
<li><code>path</code> <em>(String)</em>: &#x6355;&#x83B7;&#x7684;&#x8DEF;&#x5F84; (<code>/socket.io</code>)</li>
<li><code>serveClient</code> <em>(Boolean)</em>: &#x662F;&#x5426;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#x6587;&#x4EF6; (<code>true</code>)</li>
<li><code>adapter</code> <em>(Adapter)</em>: &#x9002;&#x914D;&#x5668;&#x4F7F;&#x7528;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;&#x4E00;&#x4E2A;`Adapter&apos;&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B83;&#x5E26;&#x6709;&#x57FA;&#x4E8E;&#x5185;&#x5B58;&#x7684;socket.io&#x3002;&#x53C2;&#x89C1;<a href="https://github.com/socketio/socket.io-adapter" target="_blank">socket.io-adapter</a></li>
<li><code>origins</code> <em>(String)</em>: &#x5141;&#x8BB8;&#x7684;&#x6E90; (<code>*</code>)</li>
<li><code>allowRequest</code> <em>(Function)</em>: &#x63A5;&#x6536;&#x7ED9;&#x5B9A;&#x63E1;&#x624B;&#x6216;&#x5347;&#x7EA7;&#x8BF7;&#x6C42;&#x4F5C;&#x4E3A;&#x5176;&#x7B2C;&#x4E00;&#x53C2;&#x6570;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x51B3;&#x5B9A;&#x662F;&#x5426;&#x7EE7;&#x7EED;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x51B3;&#x5B9A;&#x7684;&#x4FE1;&#x606F;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#xFF1A;<code>fn&#xFF08;err&#xFF0C;success&#xFF09;</code>&#xFF0C;&#x5176;&#x4E2D;<code>success</code>&#x662F;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x5176;&#x4E2D;false&#x8868;&#x793A;&#x8BF7;&#x6C42;&#x88AB;&#x62D2;&#x7EDD;&#xFF0C;err&#x662F;&#x9519;&#x8BEF;&#x4EE3;&#x7801;&#x3002;</li>
<li><code>parser</code> <em>(Parser)</em>: &#x89E3;&#x6790;&#x5668;&#x4F7F;&#x7528;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;&#x5E26;&#x6709;socket.io&#x7684;`Parser&apos;&#x5B9E;&#x4F8B;&#x3002;&#x53C2;&#x89C1;<a href="https://github.com/socketio/socket.io-parser" target="_blank">socket.io-parser</a>&#x3002;</li>
</ul>
</li>
</ul>
<p>&#x521B;&#x5EFA;:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
<span class="hljs-comment">// or</span>
<span class="hljs-keyword">var</span> Server = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>);
<span class="hljs-keyword">var</span> io = <span class="hljs-keyword">new</span> Server();
</code></pre>
<p>&#x4F20;&#x9012;&#x7ED9;socket.io&#x7684;&#x76F8;&#x540C;&#x9009;&#x9879;&#x59CB;&#x7EC8;&#x4F20;&#x9012;&#x5230;&#x521B;&#x5EFA;&#x7684; <code>engine.io</code> &#x670D;&#x52A1;&#x5668;&#x3002;&#x8BF7;&#x53C2;&#x89C1;<a href="https://github.com/socketio/engine.io#methods-1" target="_blank">options</a>&#x9009;&#x9879;&#x4F5C;&#x4E3A;&#x53C2;&#x8003;&#x3002;</p>
<p>&#x5728;&#x8FD9;&#x4E9B;&#x9009;&#x9879;&#x4E2D;:</p>
<ul>
<li><code>pingTimeout</code> <em>(Number)</em>: &#x591A;&#x5C11;ms&#x6CA1;&#x6709;pong&#x5305;&#x8003;&#x8651;&#x8FDE;&#x63A5;&#x5173;&#x95ED; (<code>60000</code>)</li>
<li><code>pingInterval</code> <em>(Number)</em>: &#x5728;&#x53D1;&#x9001;&#x65B0;&#x7684;ping&#x6570;&#x636E;&#x5305;&#x4E4B;&#x524D;&#x591A;&#x5C11;ms (<code>25000</code>).</li>
</ul>
<p>&#x8FD9;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x5C06;&#x5F71;&#x54CD;&#x5BA2;&#x6237;&#x7AEF;&#x77E5;&#x9053;&#x670D;&#x52A1;&#x5668;&#x4E0D;&#x518D;&#x53EF;&#x7528;&#x4E4B;&#x524D;&#x7684;&#x5EF6;&#x8FDF;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x7531;&#x4E8E;&#x7F51;&#x7EDC;&#x95EE;&#x9898;&#xFF0C;&#x5E95;&#x5C42;TCP&#x8FDE;&#x63A5;&#x672A;&#x6B63;&#x786E;&#x5173;&#x95ED;&#xFF0C;&#x5219;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x80FD;&#x5FC5;&#x987B;&#x7B49;&#x5230;<code>pingTimeout + pingInterval</code> ms&#x624D;&#x80FD;&#x5F97;&#x5230;<code>disconnect</code>&#x4E8B;&#x4EF6;&#x3002;</p>
<ul>
<li><code>transports</code> <em>(Array<string>)</string></em>: &#x4F20;&#x8F93;&#x5141;&#x8BB8;&#x8FDE;&#x63A5;&#x5230;&#xFF08;<code>[&apos;polling&apos;&#xFF0C;&apos;websocket&apos;]</code>&#xFF09;&#x3002;</li>
</ul>
<p><strong>Note:</strong> &#x987A;&#x5E8F;&#x5F88;&#x91CD;&#x8981;&#x3002;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x9996;&#x5148;&#x5EFA;&#x7ACB;&#x957F;&#x8F6E;&#x8BE2;&#x8FDE;&#x63A5;&#xFF0C;&#x7136;&#x540E;&#x5C3D;&#x53EF;&#x80FD;&#x5347;&#x7EA7;&#x5230;WebSocket&#x3002;&#x4F7F;&#x7528;<code>[&apos;websocket&apos;]</code>&#x610F;&#x5473;&#x7740;&#x5982;&#x679C;&#x65E0;&#x6CD5;&#x6253;&#x5F00;WebSocket&#x8FDE;&#x63A5;&#xFF0C;&#x5219;&#x4E0D;&#x4F1A;&#x6709;&#x56DE;&#x9000;&#x3002;</p>
<h4 id="new-serverport-options">new Server(port[, options])</h4>
<ul>
<li><code>port</code> <em>(Number)</em> &#x4E00;&#x4E2A;&#x8981;&#x76D1;&#x542C;&#x7684;&#x7AEF;&#x53E3;&#xFF08;&#x4E00;&#x4E2A;&#x65B0;&#x7684;http.Server&#x5C06;&#x88AB;&#x521B;&#x5EFA;&#xFF09;</li>
<li><code>options</code> <em>(Object)</em></li>
</ul>
<p>&#x8BF7;&#x770B; <a href="#new-serverhttpserver-options">above</a> &#x83B7;&#x5F97;&#x9009;&#x9879;.</p>
<h4 id="new-serveroptions">new Server(options)</h4>
<ul>
<li><code>options</code> <em>(Object)</em></li>
</ul>
<p>&#x8BF7;&#x770B; <a href="#new-serverhttpserver-options">above</a> &#x83B7;&#x5F97;&#x9009;&#x9879;.</p>
<h4 id="serversockets">server.sockets</h4>
<ul>
<li><em>(Namespace)</em></li>
</ul>
<p>&#x9ED8;&#x8BA4;(<code>/</code>)&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;</p>
<h4 id="serverserveclientvalue">server.serveClient([value])</h4>
<ul>
<li><code>value</code> <em>(Boolean)</em></li>
<li><strong>Returns</strong> <code>Server|Boolean</code></li>
</ul>
<p>&#x5982;&#x679C;<code>value</code>&#x4E3A;<code>true</code>&#xFF0C;&#x5219;&#x9644;&#x52A0;&#x7684;&#x670D;&#x52A1;&#x5668;&#xFF08;&#x89C1;<code>Server&#xFF03;attach</code>&#xFF09;&#x5C06;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#x6587;&#x4EF6;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;<code>true</code>&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x5728;&#x8C03;&#x7528;<code>attach</code>&#x540E;&#x6CA1;&#x6709;&#x6548;&#x679C;&#x3002;&#x5982;&#x679C;&#x672A;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x5C06;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x503C;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// pass a server and the `serveClient` option</span>
<span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)(http, { serveClient: <span class="hljs-literal">false</span> });

<span class="hljs-comment">// or pass no server and then you can call the method</span>
<span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.serveClient(<span class="hljs-literal">false</span>);
io.attach(http);
</code></pre>
<h4 id="serverpathvalue">server.path([value])</h4>
<ul>
<li><code>value</code> <em>(String)</em></li>
<li><strong>Returns</strong> <code>Server|String</code></li>
</ul>
<p>&#x8BBE;&#x7F6E;&#x8DEF;&#x5F84;<code>value</code>&#x4E0B;&#x7684;<code>engine.io&apos;&#x548C;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x5C06;&#x88AB;&#x63D0;&#x4F9B;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;</code>/ socket.io&apos;&#x3002;&#x5982;&#x679C;&#x672A;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x5C06;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x503C;&#x3002;</p>
<h4 id="serveradaptervalue">server.adapter([value])</h4>
<ul>
<li><code>value</code> <em>(Adapter)</em></li>
<li><strong>Returns</strong> <code>Server|Adapter</code></li>
</ul>
<p>&#x8BBE;&#x7F6E;&#x9002;&#x914D;&#x5668;&apos;value&apos;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;&#x4E00;&#x4E2A;`Adapter&apos;&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B83;&#x5E26;&#x6709;&#x57FA;&#x4E8E;&#x5185;&#x5B58;&#x7684;socket.io&#x3002;&#x53C2;&#x89C1;<a href="https://github.com/socketio/socket.io-adapter" target="_blank">socket.io-adapter</a>&#x3002;&#x5982;&#x679C;&#x672A;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x5C06;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x503C;&#x3002;</p>
<h4 id="serveroriginsvalue">server.origins([value])</h4>
<ul>
<li><code>value</code> <em>(String)</em></li>
<li><strong>Returns</strong> <code>Server|String</code></li>
</ul>
<p>&#x8BBE;&#x7F6E;&#x5141;&#x8BB8;&#x7684;&#x8D77;&#x70B9;<code>value</code>&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;&#x5141;&#x8BB8;&#x4EFB;&#x4F55;&#x6765;&#x6E90;&#x3002;&#x5982;&#x679C;&#x672A;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x5C06;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x503C;&#x3002;</p>
<h4 id="serveroriginsfn">server.origins(fn)</h4>
<ul>
<li><code>fn</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Server</code></li>
</ul>
<p>&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;origin&#xFF1A;String&#x548C;<code>callback&#xFF08;error&#xFF0C;success&#xFF09;&apos;&#xFF0C;&#x5176;&#x4E2D;</code>success`&#x662F;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8868;&#x793A;&#x662F;&#x5426;&#x5141;&#x8BB8;origin&#x3002;</p>
<p><strong>Potential defectss</strong>&#xFF1A;<em>&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5F53;&#x4E0D;&#x53EF;&#x80FD;&#x786E;&#x5B9A;&#x201C;origin&#x201D;&#x65F6;&#xFF0C;&#x5B83;&#x53EF;&#x80FD;&#x5177;&#x6709;`</em><code>*&#x7684;&#x503C;&#x3002;&#x7531;&#x4E8E;&#x6B64;&#x51FD;&#x6570;&#x5C06;&#x5BF9;&#x6BCF;&#x4E2A;&#x8BF7;&#x6C42;&#x6267;&#x884C;&#xFF0C;&#x56E0;&#x6B64;&#x5EFA;&#x8BAE;&#x4F7F;&#x6B64;&#x51FD;&#x6570;&#x5C3D;&#x53EF;&#x80FD;&#x5FEB;&#x5730;&#x5DE5;&#x4F5C;*&#x5982;&#x679C;</code>socket.io<code>&#x4E0E;</code>Express<code>&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#xFF0C;CORS&#x5934;&#x6587;&#x4EF6;&#x53EA;&#x4F1A;&#x5F71;&#x54CD;</code>socket.io`&#x8BF7;&#x6C42;&#x3002;&#x5BF9;&#x4E8E;Express&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<a href="https://github.com/expressjs/cors" target="_blank">cors</a>&#x3002;</p>
<h4 id="serverattachhttpserver-options">server.attach(httpServer[, options])</h4>
<ul>
<li><code>httpServer</code> <em>(http.Server)</em> &#x8981;&#x9644;&#x52A0;&#x5230;&#x7684;&#x670D;&#x52A1;&#x5668;</li>
<li><code>options</code> <em>(Object)</em></li>
</ul>
<p>&#x4F7F;&#x7528;&#x63D0;&#x4F9B;&#x7684;<code>options</code>&#xFF08;&#x53EF;&#x9009;&#xFF09;&#x5C06;<code>Server</code>&#x9644;&#x52A0;&#x5230;<code>httpServer</code>&#x4E0A;&#x7684;&#x4E00;&#x4E2A;engine.io&#x5B9E;&#x4F8B;&#x3002;</p>
<h3 id="serverattachport-options">server.attach(port[, options])</h3>
<ul>
<li><code>port</code> <em>(Number)</em> &#x7AEF;&#x53E3;&#x76D1;&#x542C;</li>
<li><code>options</code> <em>(Object)</em></li>
</ul>
<p>&#x4F7F;&#x7528;&#x63D0;&#x4F9B;&#x7684;<code>options</code>&#xFF08;&#x53EF;&#x9009;&#xFF09;&#x5C06;<code>Server</code>&#x9644;&#x52A0;&#x5230;&#x4E00;&#x4E2A;&#x65B0;&#x7684;http.Server&#x4E0A;&#x7684;&#x4E00;&#x4E2A;engine.io&#x5B9E;&#x4F8B;&#x3002;</p>
<h4 id="serverlistenhttpserver-options">server.listen(httpServer[, options])</h4>
<p>&#x540C; <a href="#serverattachhttpserver-options">server.attach(httpServer[, options])</a>.</p>
<h4 id="serverlistenport-options">server.listen(port[, options])</h4>
<p>&#x540C; <a href="#serverattachport-options">server.attach(port[, options])</a>.</p>
<h4 id="serverbindengine">server.bind(engine)</h4>
<ul>
<li><code>engine</code> <em>(engine.Server)</em></li>
<li><strong>Returns</strong> <code>Server</code></li>
</ul>
<p>&#x4EC5;&#x9650;&#x9AD8;&#x7EA7;&#x4F7F;&#x7528;&#x3002;&#x5C06;&#x670D;&#x52A1;&#x5668;&#x7ED1;&#x5B9A;&#x5230;&#x7279;&#x5B9A;&#x7684;engine.io<code>Server</code>&#xFF08;&#x6216;&#x517C;&#x5BB9;&#x7684;API&#xFF09;&#x5B9E;&#x4F8B;&#x3002;</p>
<h4 id="serveronconnectionsocket">server.onconnection(socket)</h4>
<ul>
<li><code>socket</code> <em>(engine.Socket)</em></li>
<li><strong>Returns</strong> <code>Server</code></li>
</ul>
<p>&#x4EC5;&#x9650;&#x9AD8;&#x7EA7;&#x4F7F;&#x7528;&#x3002;&#x4ECE;&#x4F20;&#x5165;&#x7684;engine.io&#xFF08;&#x6216;&#x517C;&#x5BB9;&#x7684;API&#xFF09;<code>Socket</code>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;`socket.io&apos;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<h4 id="serverofnsp">server.of(nsp)</h4>
<ul>
<li><code>nsp</code> <em>(String)</em></li>
<li><strong>Returns</strong> <code>Namespace</code></li>
</ul>
<p>&#x901A;&#x8FC7;&#x5176;&#x8DEF;&#x5F84;&#x540D;&#x6807;&#x8BC6;&#x7B26;<code>nsp</code>&#x521D;&#x59CB;&#x5316;&#x548C;&#x68C0;&#x7D22;&#x7ED9;&#x5B9A;&#x7684;<code>Namespace</code>&#x3002;&#x5982;&#x679C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5DF2;&#x7ECF;&#x88AB;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5B83;&#x7ACB;&#x5373;&#x8FD4;&#x56DE;&#x5B83;&#x3002;</p>
<h4 id="serverclosecallback">server.close([callback])</h4>
<ul>
<li><code>callback</code> <em>(Function)</em></li>
</ul>
<p>&#x5173;&#x95ED;socket.io&#x670D;&#x52A1;&#x5668;&#x3002; <code>callback</code>&#x53C2;&#x6570;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x5F53;&#x6240;&#x6709;&#x8FDE;&#x63A5;&#x5173;&#x95ED;&#x65F6;&#x5C06;&#x88AB;&#x8C03;&#x7528;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> Server = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>);
<span class="hljs-keyword">var</span> PORT   = <span class="hljs-number">3030</span>;
<span class="hljs-keyword">var</span> server = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>).Server();

<span class="hljs-keyword">var</span> io = Server(PORT);

io.close(); <span class="hljs-comment">// Close current server</span>

server.listen(PORT); <span class="hljs-comment">// PORT is free to use</span>

io = Server(server);
</code></pre>
<h3 id="namespace">Namespace</h3>
<p>&#x8868;&#x793A;&#x5728;&#x7531;&#x8DEF;&#x5F84;&#x540D;&#x6807;&#x8BC6;&#x7684;&#x7ED9;&#x5B9A;&#x8303;&#x56F4;&#x4E0B;&#x8FDE;&#x63A5;&#x7684;&#x5957;&#x63A5;&#x5B57;&#x6C60;&#xFF08;&#x4F8B;&#x5982;&#xFF1A;<code>/ chat</code>&#xFF09;&#x3002;</p>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x603B;&#x662F;&#x8FDE;&#x63A5;&#x5230;<code>/</code>&#x3002;</p>
<h4 id="namespacename">namespace.name</h4>
<ul>
<li><em>(String)</em></li>
</ul>
<p>&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6807;&#x8BC6;&#x7B26;&#x5C5E;&#x6027;&#x3002;</p>
<h4 id="namespaceconnected">namespace.connected</h4>
<ul>
<li><em>(Object<socket>)</socket></em></li>
</ul>
<p>&#x8FDE;&#x63A5;&#x5230;&#x6B64;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;<code>Socket</code>&#x5BF9;&#x8C61;&#x7684;&#x6563;&#x5217;&#xFF0C;&#x7531;&#x201C;id&#x201D;&#x7D22;&#x5F15;&#x3002;</p>
<h4 id="namespaceemiteventname-args">namespace.emit(eventName[, ...args])</h4>
<ul>
<li><code>eventName</code> <em>(String)</em></li>
<li><code>args</code></li>
</ul>
<p>&#x5411;&#x6240;&#x6709;&#x8FDE;&#x63A5;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x4E8B;&#x4EF6;&#x3002;&#x4EE5;&#x4E0B;&#x4E24;&#x4E2A;&#x662F;&#x7B49;&#x6548;&#x7684;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();

io.emit(<span class="hljs-string">&apos;an event sent to all connected clients&apos;</span>); <span class="hljs-comment">// main namespace</span>

<span class="hljs-keyword">var</span> chat = io.of(<span class="hljs-string">&apos;/chat&apos;</span>);
chat.emit(<span class="hljs-string">&apos;an event sent to all connected clients in chat namespace&apos;</span>);
</code></pre>
<h4 id="namespaceclientscallback">namespace.clients(callback)</h4>
<ul>
<li><code>callback</code> <em>(Function)</em></li>
</ul>
<p>&#x83B7;&#x53D6;&#x8FDE;&#x63A5;&#x5230;&#x6B64;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF08;&#x8DE8;&#x6240;&#x6709;&#x8282;&#x70B9;&#xFF08;&#x5982;&#x679C;&#x9002;&#x7528;&#xFF09;&#xFF09;&#x7684;&#x5BA2;&#x6237;&#x7AEF;ID&#x7684;&#x5217;&#x8868;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.of(<span class="hljs-string">&apos;/chat&apos;</span>).clients(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">error, clients</span>)</span>{
  <span class="hljs-keyword">if</span> (error) <span class="hljs-keyword">throw</span> error;
  <span class="hljs-built_in">console</span>.log(clients); <span class="hljs-comment">// =&gt; [PZDoMHjiu8PYfRiKAAAF, Anw2LatarvGVVXEIAAAD]</span>
});
</code></pre>
<p>&#x5728;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x623F;&#x95F4;&#x4E2D;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.of(<span class="hljs-string">&apos;/chat&apos;</span>).in(<span class="hljs-string">&apos;general&apos;</span>).clients(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">error, clients</span>)</span>{
  <span class="hljs-keyword">if</span> (error) <span class="hljs-keyword">throw</span> error;
  <span class="hljs-built_in">console</span>.log(clients); <span class="hljs-comment">// =&gt; [Anw2LatarvGVVXEIAAAD]</span>
});
</code></pre>
<p>&#x4E0E;&#x5E7F;&#x64AD;&#x4E00;&#x6837;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x662F;&#x6765;&#x81EA;&#x9ED8;&#x8BA4;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF08;&apos;/&apos;&#xFF09;&#x7684;&#x6240;&#x6709;&#x5BA2;&#x6237;&#x7AEF;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.clients(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">error, clients</span>)</span>{
  <span class="hljs-keyword">if</span> (error) <span class="hljs-keyword">throw</span> error;
  <span class="hljs-built_in">console</span>.log(clients); <span class="hljs-comment">// =&gt; [6em3d4TJP8Et9EMNAAAA, G5p55dHhGgUnLUctAAAB]</span>
});
</code></pre>
<h4 id="namespaceusefn">namespace.use(fn)</h4>
<ul>
<li><code>fn</code> <em>(Function)</em></li>
</ul>
<p>&#x6CE8;&#x518C;&#x4E00;&#x4E2A;&#x4E2D;&#x95F4;&#x4EF6;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x4E3A;&#x6BCF;&#x4E2A;&#x4F20;&#x5165;&#x7684;&#x201C;Socket&#x201D;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x63A5;&#x6536;&#x5957;&#x63A5;&#x5B57;&#x548C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x9009;&#x5730;&#x5C06;&#x6267;&#x884C;&#x63A8;&#x8FDF;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x6CE8;&#x518C;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x3002;</p>
<p>&#x4F20;&#x9012;&#x7ED9;&#x4E2D;&#x95F4;&#x4EF6;&#x56DE;&#x8C03;&#x7684;&#x9519;&#x8BEF;&#x4F5C;&#x4E3A;&#x7279;&#x6B8A;&#x7684;&#x201C;&#x9519;&#x8BEF;&#x201D;&#x5305;&#x53D1;&#x9001;&#x5230;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.use(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">socket, next</span>)</span>{
  <span class="hljs-keyword">if</span> (socket.request.headers.cookie) <span class="hljs-keyword">return</span> next();
  next(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;Authentication error&apos;</span>));
});
</code></pre>
<h4 id="event-connect">Event: &apos;connect&apos;</h4>
<ul>
<li><code>error</code> <em>(Object)</em> error object</li>
</ul>
<p>&#x5728;&#x91CD;&#x65B0;&#x8FDE;&#x63A5;&#x5C1D;&#x8BD5;&#x9519;&#x8BEF;&#x65F6;&#x89E6;&#x53D1;&#x3002;</p>
<h4 id="event-connection">Event: &apos;connection&apos;</h4>
<p>Synonym of <a href="#event-connect">Event: &apos;connect&apos;</a>.</p>
<h4 id="flag-volatile">Flag: &apos;volatile&apos;</h4>
<p>&#x4E3A;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x8BBE;&#x7F6E;&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x5982;&#x679C;&#x5BA2;&#x6237;&#x7AEF;&#x672A;&#x51C6;&#x5907;&#x597D;&#x63A5;&#x6536;&#x6D88;&#x606F;&#xFF0C;&#x5219;&#x53EF;&#x80FD;&#x4F1A;&#x4E22;&#x5931;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#xFF08;&#x56E0;&#x4E3A;&#x7F51;&#x7EDC;&#x901F;&#x5EA6;&#x6162;&#x6216;&#x5176;&#x4ED6;&#x95EE;&#x9898;&#xFF0C;&#x6216;&#x8005;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x901A;&#x8FC7;&#x957F;&#x8F6E;&#x8BE2;&#x8FDE;&#x63A5;&#x5E76;&#x5904;&#x4E8E;&#x8BF7;&#x6C42;&#x4E2D;&#x95F4;&#xFF09; - &#x54CD;&#x5E94;&#x5FAA;&#x73AF;&#xFF09;&#x3002;</p>
<pre><code class="lang-js">io.volatile.emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> }); <span class="hljs-comment">// the clients may or may not receive it</span>
</code></pre>
<h4 id="flag-local">Flag: &apos;local&apos;</h4>
<p>&#x8BBE;&#x7F6E;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x53EA;&#x6709;<em>broadcast</em>&#x5230;&#x5F53;&#x524D;&#x8282;&#x70B9;(&#x5F53;&#x4F7F;&#x7528;<a href="https://github.com/socketio/socket.io-redis" target="_blank">Redis&#x9002;&#x914D;&#x5668;</a>&#x65F6;)&#x7684;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x7684;&#x4FEE;&#x6539;&#x5668;&#x3002;</p>
<pre><code class="lang-js">io.local.emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> });
</code></pre>
<h3 id="socket">Socket</h3>
<p><code>Socket</code>&#x662F;&#x4E0E;&#x6D4F;&#x89C8;&#x5668;&#x5BA2;&#x6237;&#x7AEF;&#x4EA4;&#x4E92;&#x7684;&#x57FA;&#x672C;&#x7C7B;&#x3002; <code>Socket</code>&#x5C5E;&#x4E8E;&#x67D0;&#x4E2A;<code>Namespace</code>&#xFF08;&#x9ED8;&#x8BA4;&#x4E3A;<code>/</code>&#xFF09;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;&#x5E95;&#x5C42;&#x7684;<code>Client</code>&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#x3002;</p>
<p>&#x5E94;&#x8BE5;&#x6CE8;&#x610F;&#xFF0C;<code>Socket</code>&#x4E0D;&#x76F4;&#x63A5;&#x4E0E;&#x5B9E;&#x9645;&#x7684;&#x5E95;&#x5C42;TCP / IP<code>socket</code>&#x76F8;&#x5173;&#xFF0C;&#x5B83;&#x53EA;&#x662F;&#x7C7B;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<p>&#x5728;&#x6BCF;&#x4E2A;<code>Namespace</code>&#x4E2D;&#xFF0C;&#x4F60;&#x8FD8;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4EFB;&#x610F;&#x901A;&#x9053;&#xFF08;&#x79F0;&#x4E3A;<code>room</code>&#xFF09;&#xFF0C;<code>Socket</code>&#x53EF;&#x4EE5;&#x52A0;&#x5165;&#x548C;&#x79BB;&#x5F00;&#x3002;&#x8FD9;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5E7F;&#x64AD;&#x5230;&#x4E00;&#x7EC4;<code>Socket</code>s&#xFF08;&#x89C1;&#x4E0B;&#x9762;&#x7684;Socket&#xFF03;to&#xFF09;</p>
<h4 id="socketid">socket.id</h4>
<ul>
<li><em>(String)</em></li>
</ul>
<p>&#x4F1A;&#x8BDD;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;&#x6765;&#x81EA;&#x5E95;&#x5C42;&#x7684;&#x201C;&#x5BA2;&#x6237;&#x7AEF;&#x201D;&#x3002;</p>
<h4 id="socketrooms">socket.rooms</h4>
<ul>
<li><em>(Object)</em></li>
</ul>
<p>&#x6807;&#x8BC6;&#x6B64;&#x5BA2;&#x6237;&#x7AEF;&#x6240;&#x5728;&#x7684;&#x623F;&#x95F4;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x54C8;&#x5E0C;&#xFF0C;&#x6309;&#x623F;&#x95F4;&#x540D;&#x79F0;&#x7D22;&#x5F15;&#x3002;</p>
<h4 id="socketclient">socket.client</h4>
<ul>
<li><em>(Client)</em></li>
</ul>
<p>&#x5F15;&#x7528;&#x5E95;&#x5C42;&#x7684;<code>Client</code>&#x5BF9;&#x8C61;&#x3002;</p>
<h4 id="socketconn">socket.conn</h4>
<ul>
<li><em>(engine.Socket)</em></li>
</ul>
<p>&#x5F15;&#x7528;&#x5E95;&#x5C42;&#x7684;<code>Client</code>&#x4F20;&#x8F93;&#x8FDE;&#x63A5;&#xFF08;engine.io<code>Socket</code>&#x5BF9;&#x8C61;&#xFF09;&#x3002;&#x8FD9;&#x5141;&#x8BB8;&#x8BBF;&#x95EE;IO&#x4F20;&#x8F93;&#x5C42;&#xFF0C;&#x8FD9;&#x4ECD;&#x7136;&#xFF08;&#x4E3B;&#x8981;&#xFF09;&#x62BD;&#x8C61;&#x5B9E;&#x9645;&#x7684;TCP / IP&#x5957;&#x63A5;&#x5B57;&#x3002;</p>
<h4 id="socketrequest">socket.request</h4>
<ul>
<li><em>(Request)</em></li>
</ul>
<p>&#x4E00;&#x4E2A;getter&#x4EE3;&#x7406;&#xFF0C;&#x5B83;&#x8FD4;&#x56DE;&#x5BF9;&#x201C;&#x8BF7;&#x6C42;&#x201D;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x8BE5;&#x5F15;&#x7528;&#x6E90;&#x4E8E;&#x5E95;&#x5C42;&#x7684;engine.io&#x201C;Client&#x201D;&#x3002;&#x7528;&#x4E8E;&#x8BBF;&#x95EE;&#x8BF7;&#x6C42;&#x5934;&#xFF0C;&#x4F8B;&#x5982;<code>Cookie</code>&#x6216;<code>User-Agent</code>&#x3002;</p>
<h4 id="socketusefn">socket.use(fn)</h4>
<ul>
<li><code>fn</code> <em>(Function)</em></li>
</ul>
<p>&#x6CE8;&#x518C;&#x4E2D;&#x95F4;&#x4EF6;&#xFF0C;&#x5B83;&#x662F;&#x4E3A;&#x6BCF;&#x4E2A;&#x4F20;&#x5165;&#x7684;&#x201C;&#x6570;&#x636E;&#x5305;&#x201D;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x63A5;&#x6536;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x7684;&#x6570;&#x636E;&#x5305;&#x548C;&#x53EF;&#x9009;&#x5730;&#x5C06;&#x6267;&#x884C;&#x63A8;&#x8FDF;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x6CE8;&#x518C;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x4F20;&#x9012;&#x7ED9;&#x4E2D;&#x95F4;&#x4EF6;&#x56DE;&#x8C03;&#x7684;&#x9519;&#x8BEF;&#x4F5C;&#x4E3A;&#x7279;&#x6B8A;&#x7684;&#x201C;&#x9519;&#x8BEF;&#x201D;&#x5305;&#x53D1;&#x9001;&#x5230;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">socket</span>)</span>{
  socket.use(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">packet, next</span>)</span>{
    <span class="hljs-keyword">if</span> (packet.doge === <span class="hljs-literal">true</span>) <span class="hljs-keyword">return</span> next();
    next(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;Not a doge error&apos;</span>));
  });
});
</code></pre>
<h4 id="socketsendargs-ack">socket.send([...args][, ack])</h4>
<ul>
<li><code>args</code></li>
<li><code>ack</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code></li>
</ul>
<p>&#x53D1;&#x9001;<code>message</code>&#x4E8B;&#x4EF6;&#x3002;&#x53C2;&#x89C1;[socket.emit&#xFF08;eventName [&#xFF0C;... args] [&#xFF0C;ack]&#xFF09;]&#xFF08;&#xFF03;socketemiteventname-args-ack&#xFF09;&#x3002;</p>
<h4 id="socketemiteventname-args-ack">socket.emit(eventName[, ...args][, ack])</h4>
<ul>
<li><code>eventName</code> <em>(String)</em></li>
<li><code>args</code></li>
<li><code>ack</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code></li>
</ul>
<p>&#x5C06;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x53D1;&#x9001;&#x5230;&#x7531;&#x5B57;&#x7B26;&#x4E32;&#x540D;&#x79F0;&#x6807;&#x8BC6;&#x7684;&#x5957;&#x63A5;&#x5B57;&#x3002;&#x53EF;&#x4EE5;&#x5305;&#x62EC;&#x4EFB;&#x4F55;&#x5176;&#x5B83;&#x53C2;&#x6570;&#x3002;&#x652F;&#x6301;&#x6240;&#x6709;&#x53EF;&#x4E32;&#x884C;&#x5316;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;&#x5305;&#x62EC;<code>Buffer</code>&#x3002;</p>
<pre><code class="lang-js">socket.emit(<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;world&apos;</span>);
socket.emit(<span class="hljs-string">&apos;with-binary&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-string">&apos;2&apos;</span>, { <span class="hljs-number">3</span>: <span class="hljs-string">&apos;4&apos;</span>, <span class="hljs-number">5</span>: <span class="hljs-keyword">new</span> Buffer(<span class="hljs-number">6</span>) });
</code></pre>
<p><code>ack</code>&#x53C2;&#x6570;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x5C06;&#x4F7F;&#x7528;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x7B54;&#x6848;&#x8C03;&#x7528;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">client</span>)</span>{
  client.emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> });

  client.emit(<span class="hljs-string">&apos;ferret&apos;</span>, <span class="hljs-string">&apos;tobi&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(data); <span class="hljs-comment">// data will be &apos;woot&apos;</span>
  });

  <span class="hljs-comment">// the client code</span>
  <span class="hljs-comment">// client.on(&apos;ferret&apos;, function (name, fn) {</span>
  <span class="hljs-comment">//   fn(&apos;woot&apos;);</span>
  <span class="hljs-comment">// });</span>

});
</code></pre>
<h4 id="socketoneventname-callback">socket.on(eventName, callback)</h4>
<ul>
<li><code>eventName</code> <em>(String)</em></li>
<li><code>callback</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code></li>
</ul>
<p>&#x6CE8;&#x518C;&#x7ED9;&#x5B9A;&#x4E8B;&#x4EF6;&#x7684;&#x65B0;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x3002;</p>
<pre><code class="lang-js">socket.on(<span class="hljs-string">&apos;news&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
  <span class="hljs-built_in">console</span>.log(data);
});
</code></pre>
<h4 id="socketjoinroom-callback">socket.join(room[, callback])</h4>
<ul>
<li><code>room</code> <em>(String)</em></li>
<li><code>callback</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code> for chaining</li>
</ul>
<p>&#x5C06;&#x5BA2;&#x6237;&#x7AEF;&#x6DFB;&#x52A0;&#x5230;&#x201C;room&#x201D;&#xFF0C;&#x5E76;&#x9009;&#x62E9;&#x6027;&#x5730;&#x89E6;&#x53D1;&#x5E26;&#x6709;&#x201C;err&#x201D;&#x7B7E;&#x540D;&#xFF08;&#x5982;&#x679C;&#x6709;&#xFF09;&#x7684;&#x56DE;&#x8C03;&#x3002;</p>
<pre><code class="lang-js">io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">socket</span>)</span>{
  socket.join(<span class="hljs-string">&apos;room 237&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">console</span>.log(socket.rooms); <span class="hljs-comment">// [ &lt;socket.id&gt;, &apos;room 237&apos; ]</span>
    io.to(<span class="hljs-string">&apos;room 237&apos;</span>, <span class="hljs-string">&apos;a new user has joined the room&apos;</span>); <span class="hljs-comment">// broadcast to everyone in the room</span>
  });
});
</code></pre>
<p>&#x52A0;&#x5165;&#x623F;&#x95F4;&#x7684;&#x673A;&#x5236;&#x7531;&#x914D;&#x7F6E;&#x7684;&#x9002;&#x914D;&#x5668;&#x5904;&#x7406;&#xFF08;&#x89C1;&#x4E0A;&#x9762;&#x7684;&#x201C;&#x670D;&#x52A1;&#x5668;&#xFF03;&#x9002;&#x914D;&#x5668;&#x201D;&#xFF09;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;<a href="https://github.com/socketio/socket.io-&#x9002;&#x914D;&#x5668;" target="_blank">socket.io-adapter</a>&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#xFF0C;&#x6BCF;&#x4E2A;&#x5957;&#x63A5;&#x5B57;&#x81EA;&#x52A8;&#x52A0;&#x5165;&#x7531;&#x6B64;id&#x6807;&#x8BC6;&#x7684;&#x623F;&#x95F4;&#xFF08;&#x89C1;&#x201C;&#x5957;&#x63A5;&#x5B57;&#xFF03;id&#x201D;&#xFF09;&#x3002;&#x8FD9;&#x4F7F;&#x5F97;&#x5411;&#x5176;&#x4ED6;&#x5957;&#x63A5;&#x5B57;&#x5E7F;&#x64AD;&#x6D88;&#x606F;&#x53D8;&#x5F97;&#x5BB9;&#x6613;&#xFF1A;</p>
<pre><code class="lang-js">io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">client</span>)</span>{
  client.on(<span class="hljs-string">&apos;say to someone&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">id, msg</span>)</span>{
    <span class="hljs-comment">// send a private message to the socket with the given id</span>
    client.broadcast.to(id).emit(<span class="hljs-string">&apos;my message&apos;</span>, msg);
  });
});
</code></pre>
<h4 id="socketjoinrooms-callback">socket.join(rooms[, callback])</h4>
<ul>
<li><code>rooms</code> <em>(Array)</em></li>
<li><code>callback</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code> for chaining</li>
</ul>
<p>&#x5C06;&#x5BA2;&#x6237;&#x7AEF;&#x6DFB;&#x52A0;&#x5230;&#x623F;&#x95F4;&#x5217;&#x8868;&#xFF0C;&#x5E76;&#x9009;&#x62E9;&#x6027;&#x5730;&#x89E6;&#x53D1;&#x5E26;&#x6709;&#x201C;err&#x201D;&#x7B7E;&#x540D;&#xFF08;&#x5982;&#x679C;&#x6709;&#xFF09;&#x7684;&#x56DE;&#x8C03;&#x3002;</p>
<h4 id="socketleaveroom-callback">socket.leave(room[, callback])</h4>
<ul>
<li><code>room</code> <em>(String)</em></li>
<li><code>callback</code> <em>(Function)</em></li>
<li><strong>Returns</strong> <code>Socket</code> for chaining</li>
</ul>
<p>&#x4ECE;<code>room</code>&#x5220;&#x9664;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x5E76;&#x9009;&#x62E9;&#x6027;&#x5730;&#x89E6;&#x53D1;&#x5E26;&#x6709;`err&apos;&#x7B7E;&#x540D;&#x7684;&#x56DE;&#x8C03;&#xFF08;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#xFF09;&#x3002;</p>
<p><strong>&#x5BA2;&#x623F;&#x5728;&#x65AD;&#x5F00;&#x65F6;&#x81EA;&#x52A8;&#x7559;&#x4E0B;</strong>&#x3002;</p>
<h4 id="sockettoroom">socket.to(room)</h4>
<ul>
<li><code>room</code> <em>(String)</em></li>
<li><strong>Returns</strong> <code>Socket</code> for chaining</li>
</ul>
<p>&#x4E3A;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x8BE5;&#x4E8B;&#x4EF6;&#x53EA;&#x6709;<em>broadcasted</em>&#x5230;&#x52A0;&#x5165;&#x7ED9;&#x5B9A;&#x201C;room&#x201D;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<p>&#x8981;&#x53D1;&#x5C04;&#x5230;&#x591A;&#x4E2A;&#x623F;&#x95F4;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8C03;&#x7528;`to&apos;&#x51E0;&#x6B21;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">client</span>)</span>{
  <span class="hljs-comment">// to one room</span>
  client.to(<span class="hljs-string">&apos;others&apos;</span>).emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> });
  <span class="hljs-comment">// to multiple rooms</span>
  client.to(<span class="hljs-string">&apos;room1&apos;</span>).to(<span class="hljs-string">&apos;room2&apos;</span>).emit(<span class="hljs-string">&apos;hello&apos;</span>);
});
</code></pre>
<h4 id="socketinroom">socket.in(room)</h4>
<p>Synonym of <a href="#sockettoroom">socket.to(room)</a>.</p>
<h4 id="socketcompressvalue">socket.compress(value)</h4>
<ul>
<li><code>value</code> <em>(Boolean)</em> &#x662F;&#x5426;&#x8DDF;&#x968F;&#x5305;&#x5C06;&#x88AB;&#x538B;&#x7F29;</li>
<li><strong>Returns</strong> <code>Socket</code> &#x94FE;&#x63A5;</li>
</ul>
<p>&#x8BBE;&#x7F6E;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x7684;&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x5982;&#x679C;&#x503C;&#x4E3A;&#x201C;true&#x201D;&#xFF0C;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x5C06;&#x53EA;&#x6709;<em>compressed</em>&#x3002;&#x5F53;&#x60A8;&#x4E0D;&#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&apos;true&apos;&#x3002;</p>
<h4 id="socketdisconnectclose">socket.disconnect(close)</h4>
<ul>
<li><code>close</code> <em>(Boolean)</em> &#x662F;&#x5426;&#x5173;&#x95ED;&#x5E95;&#x5C42;&#x8FDE;&#x63A5;</li>
<li><strong>Returns</strong> <code>Socket</code></li>
</ul>
<p>&#x65AD;&#x5F00;&#x6B64;&#x5BA2;&#x6237;&#x7AEF;&#x3002;&#x5982;&#x679C;close&#x7684;&#x503C;&#x4E3A;&#x201C;true&#x201D;&#xFF0C;&#x5219;&#x5173;&#x95ED;&#x5E95;&#x5C42;&#x8FDE;&#x63A5;&#x3002;&#x5426;&#x5219;&#xFF0C;&#x5B83;&#x53EA;&#x662F;&#x65AD;&#x5F00;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;</p>
<h4 id="flag-broadcast">Flag: &apos;broadcast&apos;</h4>
<p>&#x4E3A;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x5C06;&#x53EA;&#x6709;<em>broadcast</em>&#x5230;&#x6BCF;&#x4E2A;&#x5957;&#x63A5;&#x5B57;&#xFF0C;&#x800C;&#x662F;&#x53D1;&#x9001;&#x8005;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">socket</span>)</span>{
  socket.broadcast.emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> }); <span class="hljs-comment">// everyone gets it but the sender</span>
});
</code></pre>
<h4 id="flag-volatile">Flag: &apos;volatile&apos;</h4>
<p>&#x4E3A;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53D1;&#x5C04;&#x8BBE;&#x7F6E;&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x5982;&#x679C;&#x5BA2;&#x6237;&#x7AEF;&#x6CA1;&#x6709;&#x51C6;&#x5907;&#x597D;&#x63A5;&#x6536;&#x6D88;&#x606F;&#xFF0C;&#x5219;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x53EF;&#x80FD;&#x4F1A;&#x4E22;&#x5931;&#xFF08;&#x7531;&#x4E8E;&#x7F51;&#x7EDC;&#x901F;&#x5EA6;&#x6162;&#x6216;&#x5176;&#x4ED6;&#x95EE;&#x9898;&#xFF0C;&#x6216;&#x8005;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x901A;&#x8FC7;&#x957F;&#x8F6E;&#x8BE2;&#x8FDE;&#x63A5;&#x5E76;&#x4E14;&#x5904;&#x4E8E;&#x8BF7;&#x6C42;&#x4E2D;&#x95F4;&#xFF09; - &#x54CD;&#x5E94;&#x5FAA;&#x73AF;&#xFF09;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)();
io.on(<span class="hljs-string">&apos;connection&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">socket</span>)</span>{
  socket.volatile.emit(<span class="hljs-string">&apos;an event&apos;</span>, { some: <span class="hljs-string">&apos;data&apos;</span> }); <span class="hljs-comment">// the client may or may not receive it</span>
});
</code></pre>
<h4 id="event-disconnect">Event: &apos;disconnect&apos;</h4>
<ul>
<li><code>reason</code> <em>(String)</em> &#x65AD;&#x5F00;&#x7684;&#x539F;&#x56E0;&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x6216;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#xFF09;</li>
</ul>
<p>&#x65AD;&#x5F00;&#x65F6;&#x89E6;&#x53D1;&#x3002;</p>
<h4 id="event-error">Event: &apos;error&apos;</h4>
<ul>
<li><code>error</code> <em>(Object)</em> error object</li>
</ul>
<p>&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#x89E6;&#x53D1;&#x3002;</p>
<h4 id="event-disconnecting">Event: &apos;disconnecting&apos;</h4>
<ul>
<li><p><code>reason</code> <em>(String)</em> &#x65AD;&#x5F00;&#x8FDE;&#x63A5;&#x7684;&#x539F;&#x56E0;&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x6216;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#xFF09;&#x5F53;&#x5BA2;&#x6237;&#x7AEF;&#x5C06;&#x8981;&#x65AD;&#x5F00;&#x8FDE;&#x63A5;&#xFF08;&#x4F46;&#x5C1A;&#x672A;&#x79BB;&#x5F00;&#x5B83;&#x7684;&#x201C;&#x623F;&#x95F4;&#x201D;&#xFF09;&#x65F6;&#x89E6;&#x53D1;&#x3002;</p>
<p>&#x8FD9;&#x4E9B;&#x662F;&#x4FDD;&#x7559;&#x7684;&#x4E8B;&#x4EF6;&#xFF08;&#x8FDE;&#x540C;<code>connect</code>&#xFF0C;<code>newListener</code>&#x548C;<code>removeListener</code>&#xFF09;&#xFF0C;&#x5B83;&#x4EEC;&#x4E0D;&#x80FD;&#x7528;&#x4F5C;&#x4E8B;&#x4EF6;&#x540D;&#x3002;</p>
</li>
</ul>
<h3 id="client">Client</h3>
<p><code>Client</code>&#x7C7B;&#x8868;&#x793A;&#x4F20;&#x5165;&#x4F20;&#x8F93;&#xFF08;engine.io&#xFF09;&#x8FDE;&#x63A5;&#x3002; &#x201C;Client&#x201D;&#x53EF;&#x4EE5;&#x4E0E;&#x5C5E;&#x4E8E;&#x4E0D;&#x540C;&#x201C;Namespace&#x201D;&#x7684;&#x8BB8;&#x591A;&#x591A;&#x8DEF;&#x590D;&#x7528;<code>Socket</code>&#x76F8;&#x5173;&#x8054;&#x3002;</p>
<h4 id="clientconn">client.conn</h4>
<ul>
<li><em>(engine.Socket)</em></li>
</ul>
<p>&#x5F15;&#x7528;&#x5E95;&#x5C42;&#x7684;<code>engine.io``Socket</code>&#x8FDE;&#x63A5;&#x3002;</p>
<h4 id="clientrequest">client.request</h4>
<ul>
<li><em>(Request)</em></li>
</ul>
<p>&#x4E00;&#x4E2A;getter&#x4EE3;&#x7406;&#xFF0C;&#x8FD4;&#x56DE;&#x5BF9;&#x5F15;&#x53D1;engine.io&#x8FDE;&#x63A5;&#x7684;<code>request</code>&#x7684;&#x5F15;&#x7528;&#x3002;&#x7528;&#x4E8E;&#x8BBF;&#x95EE;&#x8BF7;&#x6C42;&#x5934;&#xFF0C;&#x4F8B;&#x5982;<code>Cookie</code>&#x6216;<code>User-Agent</code>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Introduction">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="emit.html" class="navigation navigation-next " aria-label="Next page: emit">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"socket.io API","level":"1.2","depth":1,"next":{"title":"emit","level":"1.3","depth":1,"path":"emit.md","ref":"emit.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"socket.io-api.md","mtime":"2017-03-06T14:54:10.909Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-07T13:45:59.536Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

